package com.zat.mes.andrmes.dofun.work.adapter

import android.text.Editable
import android.text.TextUtils
import android.text.TextWatcher
import android.widget.EditText
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.module.LoadMoreModule
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.zat.mes.andrmes.R
import com.zat.mes.andrmes.data.OutsourceOrderDetail

/**
 * @author zy
 * @date :2020-02-22 09:28
 * @description: 外协成品入库
 */
class InhouseOrderProductAdapter(layoutResId: Int) :
    BaseQuickAdapter<OutsourceOrderDetail, BaseViewHolder>(layoutResId), LoadMoreModule {

    //出 入库
    var inHouse = true
    override fun convert(helper: BaseViewHolder, item: OutsourceOrderDetail) {
        helper.setIsRecyclable(false)
        helper.setText(
            R.id.productColorOutSourceItem,
            context.getString(R.string.text_color) + "：" + item?.color
        )
        helper.setText(
            R.id.productSizeOutSourceItem,
            context.getString(R.string.text_size) + "：" + item?.sizeList
        )
        val etView = helper.getView<EditText>(R.id.productOutQtyOutSourceItem)

        if (inHouse) {
            etView.setText(item?.inquantity)
            helper.setText(R.id.typeOutQtyOutSourceItem,context.getString(R.string.inhouse_qty))
        }else{
            etView.setText(item?.outquantity)
            helper.setText(R.id.typeOutQtyOutSourceItem,context.getString(R.string.out_house_qty))
        }
        etView.addTextChangedListener(object :TextWatcher{
            override fun afterTextChanged(s: Editable) {
                if (!TextUtils.isEmpty(s.toString())){
                    if (inHouse){
                        item?.inquantity = s.toString()
                    }else{
                        item?.outquantity = s.toString()
                    }
                }

            }

            override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
            }

            override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
            }

        })
    }
}